<template>
	<div class="role" v-if="dialogFormVisible">
		<el-dialog :title="title" :visible="dialogFormVisible"
				   width="800px" top="5vh"
				   :close-on-click-modal="false"
				   :before-close="handleClose"
				   append-to-body>
			<div class="tab">
				<el-form ref="form" :rules="rules" :model="form" label-width="80px">

					<el-form-item label="测试结果" prop="status">
						<el-select v-model="form.status" clearable style="width: 100%;" placeholder="请选择状态">
							<el-option label="通过" value="1"></el-option>
							<el-option label="驳回" value="2"></el-option>
						</el-select>
					</el-form-item>
					<el-form-item label="备注">
						<el-input v-model="form.remark" :rows="6" type="textarea" placeholder="请输入备注"></el-input>
					</el-form-item>
				</el-form>
			</div>
			<div slot="footer" class="dialog-footer">
				<el-button @click="handleClose">取 消</el-button>
				<el-button type="primary" @click="add('form')">提 交</el-button>
			</div>
		</el-dialog>
	</div>
</template>

<script>
import { reportExamine } from '@/api/user'
export default {
	name: 'addForm',
	components:{

	},
	data(){
		return {
			dialogFormVisible:false,
			form:{

			},
			id:'',
			rules:{
				status:{required: true, message: '请选择测试结果', trigger: 'change' },
				remark: [{ required: true, message: '请输入备注', trigger: 'blur' }]
			},
			title:'结果填写',
			fatherId:''
		}
	},
	created() {
	},
	methods:{
		handleClose(){
			this.dialogFormVisible = false
			this.form = {}
		},
		add(form){
			this.$refs[form].validate((valid) => {
				let obj = {
					status:parseInt(this.form.status),
					remark:this.form.remark
				}
				console.log(obj,this.id,1212121)
				if (valid) {
					this.dialogFormVisible = false
					reportExamine(obj,this.id).then(res => {
						if(res.status == 'success'){
							this.$message.success(res.message)
							this.$parent.initTable()
							this.form = {}
						} else if(res.code == 403){
							this.$message.error('无权限操作！')
						} else {
							this.$message.error(res.message)
							this.dialogFormVisible = false
							this.form = {}
						}
					})
				} else {
					return false;
				}
			});
		},
		initData(data){
			this.id = data
			// this.form = Object.assign({},data)
		}
	}

}
</script>

<style lang="scss" scoped>
.role{

}
.step{
	margin: 10px 0;
}
.testCase{
	margin-top: 22px;
	border-top: 1px solid #eee;
	padding-top: 10px;
	height: 430px;
	overflow:scroll;
}
.testTable{
	height: 430px;
	overflow:scroll;
}
.del{
	color: #1890FF;
	cursor: pointer;
}
</style>
